<script lang="ts" setup>
import type {
  WorkbenchProjectItem,
  WorkbenchQuickNavItem,
  WorkbenchTodoItem,
  WorkbenchTrendItem,
} from '@vben/common-ui';

import { ref } from 'vue';
import { useRouter } from 'vue-router';

import {
  WorkbenchHeader,
  WorkbenchProject,
  WorkbenchQuickNav,
  WorkbenchTodo,
  WorkbenchTrends,
} from '@vben/common-ui';
import { preferences } from '@vben/preferences';
import { useUserStore } from '@vben/stores';
import { openWindow } from '@vben/utils';

const userStore = useUserStore();

// 这是一个示例数据，实际项目中需要根据实际情况进行调整
// url 也可以是内部路由，在 navTo 方法中识别处理，进行内部跳转
// 例如：url: /dashboard/workspace
const projectItems: WorkbenchProjectItem[] = [
  {
    color: '',
    content: '健康的身体是实现目标的基石。',
    date: '2021-05-01',
    group: '开源组',
    icon: 'carbon:logo-github',
    title: '订餐系统',
    url: 'http://10.10.65.218:8081/ydkj/login',
  },
  {
    color: '#3fb27f',
    content: '现在的你决定将来的你。',
    date: '2021-04-01',
    group: '算法组',
    icon: 'ion:logo-vue',
    title: '永道官网',
    url: 'https://www.arizonrfid.com/',
  },
  {
    color: '#e18525',
    content: '没有什么才能比努力更重要。',
    date: '2021-04-01',
    group: 'MES组',
    icon: 'ion:logo-html5',
    title: 'BPM',
    url: 'http://10.35.82.29:8086/NaNaWeb/',
  },
];

// 同样，这里的 url 也可以使用以 http 开头的外部链接
const quickNavItems: WorkbenchQuickNavItem[] = [
  {
    color: '#1fdaca',
    icon: 'ion:home-outline',
    title: '订餐系统',
    url: 'http://10.10.65.218:8081/ydkj/login',
  },
  {
    color: '#bf0c2c',
    icon: 'ion:grid-outline',
    title: 'BPM',
    url: 'http://10.35.82.29:8086/NaNaWeb/',
  },
  {
    color: '#e18525',
    icon: 'ion:layers-outline',
    title: '永道官网',
    url: 'https://www.arizonrfid.com/',
  },
  
];

const todoItems = ref<WorkbenchTodoItem[]>([]);
const trendItems: WorkbenchTrendItem[] = [];

const router = useRouter();

// 这是一个示例方法，实际项目中需要根据实际情况进行调整
// This is a sample method, adjust according to the actual project requirements
function navTo(nav: WorkbenchProjectItem | WorkbenchQuickNavItem) {
  if (nav.url?.startsWith('http')) {
    openWindow(nav.url);
    return;
  }
  if (nav.url?.startsWith('/')) {
    router.push(nav.url).catch((error) => {
      console.error('Navigation failed:', error);
    });
  } else {
    console.warn(`Unknown URL for navigation item: ${nav.title} -> ${nav.url}`);
  }
}
</script>

<template>
  <div class="p-5">
    <WorkbenchHeader
      :avatar="userStore.userInfo?.avatar || preferences.app.defaultAvatar"
    >
      <template #title>
        您好, {{ userStore.userInfo?.realName }}。 {{$t('authentication.pageTitle')}}，开始您一天的工作吧！
      </template>
      <template #description> 没有什么才能比努力更重要。 </template>
    </WorkbenchHeader>

    <div class="mt-5 flex flex-col lg:flex-row">
      <div class="mr-4 w-full lg:w-2/5">
        <WorkbenchQuickNav
          :items="quickNavItems"
          class="mt-5 lg:mt-0"
          title="快捷导航"
          @click="navTo"
        />
        
      </div>
      <div class="w-full lg:w-3/5">
        
        
      </div>
    </div>
  </div>
</template>
